package com.ohuang.baseapp.view.refresh.OhRefrsh;

import com.ohuang.baseapp.ResourceTable;
import ohos.agp.components.*;
import ohos.app.Context;

public class BottomFreshView extends ComponentContainer implements RefreshView {
    private Context context;
    private Text text;

    public BottomFreshView(Context context) {
        this(context, null);
    }

    public BottomFreshView(Context context, AttrSet attrSet) {
        this(context, attrSet, null);
    }

    public BottomFreshView(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        init(context);
    }

    private void init(Context context) {
        this.context=context;
        Component component = LayoutScatter
                .getInstance(context)
                .parse(ResourceTable.Layout_ohrefresh_bottom_text, null, false);
        addComponent(component);
        text= (Text) component.findComponentById(ResourceTable.Id_text);
    }

    @Override
    public void initRefresh() {
        text.setText("上拉加载更多");
    }

    @Override
    public void onRefresh(Refresh refresh) {

    }

    @Override
    public void refreshComplete() {

    }

    @Override
    public void onRelease(Refresh refresh) {
        text.setText("数据加载完成");
        context.getUITaskDispatcher().delayDispatch(new Runnable() {
            @Override
            public void run() {
                refresh.refreshComplete();
            }
        },1000);


    }
}
